package com.hoaptt.pieces;

import com.hoaptt.helper.Coordinate;
import com.hoaptt.model.Board;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




public class Horse extends Piece {

    public  Horse (PLAYER player) {
        super(player);
        this.nameA = Character.toString((char)20620);
        this.nameB = Character.toString((char)39340);
        this.alias = Piece.NAMEPIECE.horse;
   }

    @Override
    public ArrayList<Coordinate> generateMove(Board board, Coordinate loc) {
        ArrayList<Coordinate> ar = new ArrayList<Coordinate>();
        int X[] = new int[]{ 1, 1, 2,  2, -1, -1, -2, -2};
        int Y[] = new int[]{-2, 2, 1, -1, 2,  -2,  1, -1};
        for (int i = 0; i < X.length; i++) {
            Coordinate coo = new Coordinate(loc.getRow() + X[i], loc.getCol() + Y[i]);
            if (coo != null && (coo.getRow()>=0 && coo.getRow() <= 8) && (coo.getCol() >= 0 && coo.getCol() <=9) ) {
                 // check vi 2 vi tri dau tien
                if (loc.getCol() - coo.getCol() == 2 || coo.getCol() - loc.getCol() == 2 ) {
                    Coordinate m1 = new Coordinate(loc.getRow(), (loc.getCol() + coo.getCol())/2);
                    if (board.getAtLoc(m1).getAlias() == null || board.getAtLoc(m1).getAlias() == Piece.NAMEPIECE.default1 ) {
                    ar.add(coo);
                }
                }
                
                // check 2 vi tri tiep theo
                if (loc.getRow() - coo.getRow() == 2 || coo.getRow() - loc.getRow() == 2 ) {
                Coordinate m2 = new Coordinate((loc.getRow() +coo.getRow())/2, loc.getCol());
                if (board.getAtLoc(m2).getAlias() == null || board.getAtLoc(m2).getAlias() == Piece.NAMEPIECE.default1) {
                    ar.add(coo);
                }
                }
            }

        }
        return ar;
    }

}
